{*
  Object Pascal Microsoft Data Access Components manipulation routines
  @Author  Maciej Zagozda (1998-2008)
  @Licence Microsoft Reciprocal License (Ms-RL)
  @Website http://www.codeplex.com/intelitechdelphirtns/
  @Version 2008/04/20 Added documentation support
}

unit MDACRoutines;

{$ifdef VER110} // C++ Builder 3
  {$ObjExportAll On}
{$endif VER110}

interface

const
  LIBID_MDACVer: TGUID = '{54AF9343-1923-11D3-9CA4-00C04F72C514}';
  IID_IVersion: TGUID = '{54AF934F-1923-11D3-9CA4-00C04F72C514}';
  CLASS_Version: TGUID = '{54AF9350-1923-11D3-9CA4-00C04F72C514}';
type

  IVersion = interface;
  IVersionDisp = dispinterface;
  Version = IVersion;

  IVersion = interface(IDispatch)
    ['{54AF934F-1923-11D3-9CA4-00C04F72C514}']
    function Get_Major: OleVariant; safecall;
    function Get_Minor: OleVariant; safecall;
    function Get_Build: OleVariant; safecall;
    function Get_Qfe: OleVariant; safecall;
    function Get_String_: OleVariant; safecall;
    property Major: OleVariant read Get_Major;
    property Minor: OleVariant read Get_Minor;
    property Build: OleVariant read Get_Build;
    property Qfe: OleVariant read Get_Qfe;
    property String_: OleVariant read Get_String_;
  end;

  IVersionDisp = dispinterface
    ['{54AF934F-1923-11D3-9CA4-00C04F72C514}']
    property Major: OleVariant readonly dispid 1;
    property Minor: OleVariant readonly dispid 2;
    property Build: OleVariant readonly dispid 3;
    property Qfe: OleVariant readonly dispid 4;
    property String_: OleVariant readonly dispid 5;
  end;

  CoVersion = class
    class function Create: IVersion;
    class function CreateRemote(const MachineName: string): IVersion;
  end;
  
function GetMDACVersion: AnsiString;

implementation

uses ComObj, ActiveX;

class function CoVersion.Create: IVersion;
begin
  Result := CreateComObject(CLASS_Version) as IVersion;
end;

class function CoVersion.CreateRemote(const MachineName: string): IVersion;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_Version) as IVersion;
end;

function GetMDACVersion: AnsiString;
begin
  try
    CoInitialize(nil);
    Result := PChar( String(CoVersion.Create.String_));
  except
    Result := '';
  end;//try
end;

end.
